package bs.owb.interceptors;

import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;

@Interceptor
@MyTransactional
public class TransactionalInterceptor {

    @Inject
    private SimpleTransactionManager transactionManager;

    @AroundInvoke
    public Object wrapIntoTransaction(InvocationContext context) throws Exception {
        transactionManager.startTransaction();
        System.out.println("################# TRANSACTION BEGIN ##########################");
        System.out.println("---> " + context.getMethod().getName());
        Object retValue = context.proceed();
        System.out.println("################# TRANSACTION END ##########################");
        transactionManager.stopTransaction();
        return retValue;
    }


}
